package edu.neu.cs6515.admin;

import java.util.List;

import edu.neu.cs6515.player.IPlayer;
import edu.neu.cs6515.xml.Score;
import edu.neu.cs6515.xml.Tile;

/**
 * PlayerEntry represents a Player in the Administrator
 */
public class PlayerEntry implements
        Comparable<PlayerEntry> {

    private IPlayer player;
    private String name;
    private Score score;
    private List<Tile> tilesInHand;
    private boolean playerAllowedToPlay = true;
    private String reasonForDisqualification = "";

    /**
     * Constructor that initializes the entry with a player, score and tiles
     * 
     * @param player
     *            Player object for this table entry
     * @param playersName
     *            Name of the registered player
     * @param score
     *            score of this player
     * @param tilesInHand
     *            tiles currently in the hand of the player
     */
    public PlayerEntry(final IPlayer player,
            final String playersName,
            final Score score,
            final List<Tile> tilesInHand) {
        this.player = player;
        this.name = playersName;
        this.score = score;
        this.tilesInHand = tilesInHand;
    }

    /**
     * to set the playerAllowedToPlay to false and give the reason for this
     * disqualification
     * 
     * @param reason
     *            explanation for disqualification
     */
    public void disqualifyPlayer(final String reason) {
        playerAllowedToPlay = false;
        reasonForDisqualification = reason;
    }

    /**
     * @return reason-string for the disqualification
     */
    public String getReasonForDisqualification() {
        return reasonForDisqualification;
    }

    /**
     * decide is the Player allowed to play the game
     * 
     * @return true if allowed
     */
    public boolean isPlayerAllowedToPlay() {
        return playerAllowedToPlay;
    }

    public String getName() {
        return name;
    }

    public IPlayer getPlayer() {
        return player;
    }

    public Score getScore() {
        return score;
    }

    public void setScore(final Score s) {
        this.score = s;
    }

    public List<Tile> getTilesInHand() {
        return tilesInHand;
    }

    public void setTilesInHand(final List<Tile> tilesInHand) {
        this.tilesInHand = tilesInHand;
    }

    @Override
    public int compareTo(final PlayerEntry o) {
        return score.compareTo(o.getScore());
    }
}
